<!--
 * @Author: tangyongxin 1463148307@qq.com
 * @Date: 2024-01-31 20:42:09
 * @LastEditors: tangyongxin 1463148307@qq.com
 * @LastEditTime: 2024-03-03 14:13:11
 * @FilePath: \patrol_front\src\views\dashboard\PieChart.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        series: [
          {
            name: 'WEEKLY WRITE ARTICLES',
            type: 'pie',
            roseType: 'radius',
            radius: [15, 95],
            center: ['40%', '50%'],
            data: [
              { value: 320, name: '待处理', itemStyle: { color: "#FF4C55" } },
              { value: 240, name: '已完成', itemStyle: { color: '#5AD8A6' } },
              { value: 149, name: '超时', itemStyle: { color: '#5D7092' } },
              { value: 100, name: '延期', itemStyle: { color: '#F6BD16' } }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
